﻿//----------------------------------------------------------------
// Desc: 
// Edit: ShowLong, http://blog.csdn.net/showlong
//
// Date Created: 2011-06-07
//
// Update Date : 
//
// Copyright (c) Fuel4D (http://www.fuel4d.com), All rights reserved.
//
//----------------------------------------------------------------
#pragma once


//----------------------------------------------------------------
// 函数自动灯光处理类
//----------------------------------------------------------------
class FAutoLight
{
public:
    FAutoLight(IFEngine* p, bool st)
        :fge(p)
        ,state(0xFF)
    {
        if (fge->GetSunlight()->IsOpen() != st)
        {
            fge->GetSunlight()->Open(st);
            state = !st;
        }
    }
    virtual~FAutoLight()
    {
        if (state != 0xFF)
            fge->GetSunlight()->Open(state != 0);
    }
    IFEngine* fge;
    BYTE state;
};


//----------------------------------------------------------------
// 自动雾处理类
//----------------------------------------------------------------
class FAutoFog
{
public:
    FAutoFog(IFEngine* p, bool st)
        :fge(p)
        ,state(0xFF)
    {
        if (fge->GetFog()->IsOpen() != st)
        {
            fge->GetFog()->Open(st);
            state = !st;
        }
    }
    virtual~FAutoFog()
    {
        if (state != 0xFF)
            fge->GetFog()->Open(state != 0);
    }
    IFEngine* fge;
    BYTE state;
};


//----------------------------------------------------------------
// 自动引擎创建与消毁
//----------------------------------------------------------------
class FAutoEngine
{
public:
    FAutoEngine(FEngineParameter& param)
        :fge(FNewEngine())
    {
        if (fge && fge->Initialize(param))
            fge->Run();
    }
    virtual~FAutoEngine()
    {
        FDelEngine(fge);
    }
    IFEngine* fge;
};


//----------------------------------------------------------------
// 自动后背缓冲区切换
//----------------------------------------------------------------
class FAutoBackbuffer
{
public:
    FAutoBackbuffer(IFEngine* p, FIDTEXTURE tex)
        :fge(p)
    {
        push_ok = fge ? fge->GetGraph()->PushBackbuffer(tex) : false;
    }
    virtual~FAutoBackbuffer()
    {
        if (push_ok && fge)
            fge->GetGraph()->PopBackbuffer();
    }
    IFEngine* fge;
    bool push_ok;
};